using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Administration;
using CKS.Sandbox.Admin.Validators;

namespace CKS.Sandbox.Admin.Features.CKS.Sandbox.Validator
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("4dc581cc-d0fb-41e3-846a-0d814cd70912")]
    public class CKSSandboxEventReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            // get instance of the local "User Code Service"
            SPUserCodeService ucs = SPUserCodeService.Local;

            // create an instance of our validator
            CoreValidator validator = new CoreValidator(SPUserCodeService.Local);

            // add our validator to the service store
            ucs.SolutionValidators.Add(validator);
        }


        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            // get instance of the local "User Code Service"
            SPUserCodeService ucs = SPUserCodeService.Local;

            // create an instance of our validator
            CoreValidator validator = new CoreValidator(SPUserCodeService.Local);

            // remove the validator, using the GUID as a reference
            ucs.SolutionValidators.Remove(validator.GetType().GUID);
        }
    }
}
